﻿@*作业列表管理页面*@
@using EasyCourse.Model;
@{
    Layout = null;
    CommonPageInfo pageInfo = ViewData[CommonViewDataKey.CommonPageInfo] as CommonPageInfo;
    string para = "CourseId=" + pageInfo.CourseId;
}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>作业管理</title>
    @Html.Partial("~/Views/Share/PublicHeader.cshtml")
</head>
<body>
    @Html.Partial("~/Views/Share/PublicTopNav4Teacher.cshtml")
    <div class="container">
        <div class="row">
            <h1 class="topTitle-h1">@pageInfo.CourseName<br>
                <small>广州中医药大学康复治疗微课程网络学习平台</small></h1>
        </div>
    </div>
    @*导航菜单*@
    @Html.Partial("~/Views/Share/PublicTeacherNaviMenu.cshtml", 1)
    <div class="container wrap1 mainwrap">
        <div class="row">
            <div class="col-xs-2">
                <div class="dropdown theme-dropdown clearfix">
                    <a id="dropdownMenu1" href="#" role="button" class="sr-only dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                        <li class="active" role="presentation">
                            <a role="menuitem" tabindex="-1" href="/AssignmentManage/List?@para">
                                <span class="glyphicon glyphicon-th-list"></span>作业列表
                            </a>
                        </li>
                        <li role="presentation" class="divider"></li>
                        <li role="presentation">
                            <a role="menuitem" tabindex="-1" href="/AssignmentManage/Add?@para">
                                <span class="glyphicon glyphicon-plus"></span>新增作业
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="col-xs-10">
                <div class="panel panel-default mainwrap-part">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <ol class="breadcrumb">
                                <li>作业管理</li>
                                <li class="active">作业列表</li>
                            </ol>
                        </h3>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <form class="form-horizontal" role="form">
                                <div class="form-group clearfix">
                                    <div class="col-xs-3">
                                        <input type="text" class="form-control" id="courseName" placeholder="请输入作业名称">
                                    </div>
                                    <label for="courseName" class="col-xs-2 control-label">是否停用：</label>
                                    <div class="col-xs-3">
                                        <select class="form-control" id="courseSate">
                                            <option value="-1" selected>全部</option>
                                            <option value="0">是</option>
                                            <option value="1">否</option>
                                        </select>
                                    </div>
                                    <div class=" col-xs-4">
                                        <button type="button" class="btn btn-success" id="subBtn">
                                            <span class="glyphicon glyphicon-search"></span>搜索
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <table id="tb" class="table table-bordered tb1 table-striped table-hover">
                            <thead>
                                <tr>
                                    <th width="30%">作业名称</th>
                                    <th width="20%">创建时间</th>
                                    <th width="15%">是否停用</th>
                                    <th width="35%">操作</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                        <div class="row clearfix well" id="well">
                            <div class="pull-left sum" id="PagInfo"></div>
                            <div class=" center-block clearfix pull-right">
                                <ul class="pagination" id="PageTool"></ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    @Html.Partial("~/Views/Share/PublicFooter.cshtml")
    @Html.Partial("~/Views/Share/PublicCommonJs.cshtml")

    <script type="text/javascript">
        var _courseId = $.getUrlParam("CourseId"),     //课程id
            $courseName,   //课程名输入框
            $courseSate,   //课程是否停用选择框
            ele,           //表格内容区
            _courseName = "",   //课程名称
            _status = -1,  //为-1时默认全部加载
            _JlistTop,
            _state = false,
            opts = false,
            _hash = 1;
        $(document).ready(function () {
            _courseId =$.getUrlParam("CourseId"),
            ele = $("#tb tbody"),
            $courseName = $("#courseName"),
            $courseSate = $("#courseSate");
            _JlistTop = $(".wrap1").offset().top - $(".topNavPar").height(); 
            if (!!window.location.hash) {
                _hash = window.location.hash.substr(1);
                getList(_hash);
            } else {
                getList(_hash);
            }
            /*搜索时强制回到第一页*/
            $("#subBtn").click(function () { getList(1); }); 
        });
        /*获取表格数据*/
        function getList(pageNo) {
            _status = $courseSate.val(), _courseName = $courseName.val().trim();
            $.easyPost("@Url.Action("GetAssignList", "AssignmentManage")", { "PageNO": pageNo, "PageSize": "10", "CourseId": _courseId, "AssignmentName": _courseName, "Status": _status },
               function (data) {
                   var _html = ''
                   if (!data.result) {
                       showTips.open(data.message);
                       return;
                   }
                   if (data.rows.length > 0) {
                       var _row = data.rows,
                           _rowL = _row.length;
                       opts = {
                           totalPages: data.totalPage,
                           total: data.total,
                           currentPage: pageNo,
                           onPageClicked: function (event, originalEvent, type, page) {
                               getList(page);
                           }
                       }
                       initialPaginator(opts, "PageTool", "PagInfo");
                       for (var i = 0; i < _rowL; i++) {
                           var item = _row[i];
                           var state = ((item.Status == 1) ? "否" : "是");
                           var changeOpera = ((item.Status == 1) ? "停用" : "启用");;
                           var _date = "", time = "";
                           if (item.CreateTime != null) {
                               _date = item.CreateTime.replace(/\//g, "");
                               time = eval('new ' + _date).format("yyyy-MM-dd");
                           }
                           _html += '<tr>' +
                               '<td>' + item.Title +
                               '</td>' +
                           '<td>' + time + '</td>' +
                           '<td>' + state + '</td>' +
                           '<td><a class="operate" data-state="' + state + '" href="javascript:void(0)" onclick="changeState(this,\'' + item.Id + '\')"><span class="glyphicon glyphicon-stop"></span> ' + changeOpera + '</a>' +
                                        '<a class="operate" href="/AssignmentManage/Edit?AssignmentId=' + item.Id + '&CourseId=' + item.CourseId + '"><span class="glyphicon glyphicon-pencil"></span> 编辑</a>' +
                                        '<a class="operate"  href="javascript:download(\'' + item.Id + '\')"><span class="glyphicon glyphicon-circle-arrow-down"></span> 下载作业</a>' +
                                        '<a class="operate" href="/AssignmentManage/SubmitList?AssignmentId=' + item.Id + '&CourseId=' + item.CourseId + '"><span class="glyphicon glyphicon-circle-arrow-up"></span> 上交情况</a></td>' +
                           '</tr>';
                       }
                       if (_state) {
                           $('html,body').animate({ scrollTop: _JlistTop }, 0);
                       }
                       _state = true;
                       $("#well").show();

                   } else {
                       _html = "<tr><td colspan='4' align='center'>暂无内容!</tr>";
                       $("#well").hide();
                   }
                   //向tbody内部填充数据
                   ele.html(_html);
               }, "json");
        }
        /*修改“是否停用”状态*/
        function changeState(ele, id) {;
            var $this = $(ele), _da = $this.attr("data-state");
            if (_da == "是") {
                $.easyPost("@Url.Action("Start", "AssignmentManage")", { "Id": id }, function () { getList(_hash); }, "json");
                return;
            }
            else {
                $.easyPost("@Url.Action("Stop", "AssignmentManage")", { "Id": id }, function () { getList(_hash); }, "json");
                return;
            }  
        }
        //下载作业
        function download(id) {
            $.easyPost("@Url.Action("DownLoadAssignment", "AssignmentManage")", { "Id": id }, function (data) {
                if (data.result == false) {
                    showTips.open(data.message); return;
                }
                window.location.href = data.entity;
            });
        }
    </script>
</body>
</html>
